# 3-4 匹配符号
from pythonds.basic import Stack;

def matches(symbol, top):
    symbols = "([{"
    tops = ")]}"
    return symbols.index(top) == tops.index(symbol)

def parChecker(symbolString):
    index = 0  # 索引
    s = Stack()  # 栈
    balanced = True
    while index < len(symbolString) and balanced:
        symbol = symbolString[index]
        if symbol in "([{":
            s.push(symbol)
        else:
            if s.isEmpty():
                balanced = False
            else:
                top = s.pop()  # 栈顶部删除 并返回
                if not matches(symbol, top):
                    balanced = False
        index += 1
    if balanced and s.isEmpty():
        return "yes"
    else:
        return "no"

sysmbolString = "{[(])}"
print(parChecker(sysmbolString))
